Skip to content

Conversation

idegtiarenko
Copy link
Contributor

We are using IndexPattern class to represent a set of patterns in FROM p1,p2 or in LOOKUP JOIN p1.
Today it is impossible to have more than a single FROM, however we store main indices patterns in a list that leads to unnecessary complexity.
This change replaces list with a nullable field.

@idegtiarenko idegtiarenko added >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.2.0 labels Sep 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

ThreadPool.Names.SEARCH_COORDINATION,
ThreadPool.Names.SYSTEM_READ
);
// TODO we plan to support joins in the future when possible, but for now we'll just fail early if we see one
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already support lookup joins and they require a separate data structure.
Once we support nested queries they would likely need their own structure (to distinguish top level vs nested query).
Today we are guarded by grammar and parser to never have more than a single item in the list so indices.size() > 1 is effectively a dead code.

listener.onFailure(ex);
}
// occurs when dealing with local relations (row a = 1)
listener.onResponse(result.withIndexResolution(IndexResolution.invalid("[none specified]")));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing could be thrown here.

plan.forEachUp(LogicalPlan::setPreAnalyzed);

return new PreAnalysis(indexMode.get(), indices.stream().toList(), unresolvedEnriches, lookupIndices);
return new PreAnalysis(indexMode.get(), index.get(), unresolvedEnriches, lookupIndices);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like indices were copied to immutable list here. I wonder if it is worth doing the same for unresolvedEnriches and lookupIndices?

plan.forEachUp(UnresolvedRelation.class, p -> {
if (p.indexMode() == IndexMode.LOOKUP) {
lookupIndices.add(p.indexPattern());
} else if (indexMode.get() == null || indexMode.get() == p.indexMode()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover: In case that we somehow find 2 indices in the same mode, we're going to silently throw away the previous one.

There shouldn't be 2 indices. This is enforced in EsqlSession#preAnalyzeMainIndices.

IndicesExpressionGrouper indicesGrouper,
XPackLicenseState licenseState,
List<IndexPattern> patterns,
IndexPattern index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we're moving the naming back to index, but we know this is generally a pattern. Also applies to PreAnalyzer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ to what @alex-spies said, the name "index" can be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updating

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

IndicesExpressionGrouper indicesGrouper,
XPackLicenseState licenseState,
List<IndexPattern> patterns,
IndexPattern index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ to what @alex-spies said, the name "index" can be confusing.

@idegtiarenko idegtiarenko merged commit 1398524 into elastic:main Sep 5, 2025
33 checks passed
@idegtiarenko idegtiarenko deleted the simplify_preanalysis branch September 5, 2025 14:55
phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Sep 23, 2025
BASE=c05c61d38cdac9c9608d6e8989f1fa7b9ca035cb
HEAD=394aaef8034a4e09c6ef307a5ac9ac5d4f1e3f52
Branch=main
phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Oct 2, 2025
BASE=c05c61d38cdac9c9608d6e8989f1fa7b9ca035cb
HEAD=394aaef8034a4e09c6ef307a5ac9ac5d4f1e3f52
Branch=main
phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Oct 6, 2025
BASE=c05c61d38cdac9c9608d6e8989f1fa7b9ca035cb
HEAD=394aaef8034a4e09c6ef307a5ac9ac5d4f1e3f52
Branch=main
phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Oct 7, 2025
BASE=c05c61d38cdac9c9608d6e8989f1fa7b9ca035cb
HEAD=394aaef8034a4e09c6ef307a5ac9ac5d4f1e3f52
Branch=main
phananh1010 added a commit to phananh1010/elasticsearch that referenced this pull request Oct 17, 2025
BASE=c05c61d38cdac9c9608d6e8989f1fa7b9ca035cb
HEAD=394aaef8034a4e09c6ef307a5ac9ac5d4f1e3f52
Branch=main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants